﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using log4net;

public partial class Pages_USLogin : System.Web.UI.UserControl
{
    private static readonly ILog log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
    protected void Page_Load(object sender, EventArgs e)
    {
     
        lblMessage.Visible = false;
        if (HttpContext.Current.Session["User"] == null)
        {
            MultiViewLogin.ActiveViewIndex = 0;
        }
        else
        {
            MultiViewLogin.ActiveViewIndex = 1;
        }

    }
 


    protected void Button1_Click(object sender, EventArgs e)
    {
       ThanhVienBLL tv = new ThanhVienBLL();
        string email;
        string pass;
        email = txtEmail.Text.Trim();
        pass = txtMatKhau.Text.Trim();
        try
        {
            if (tv.CheckLogin(email, pass))
            {
                HttpContext.Current.Session["User"] = email;
                Response.Redirect("Default.aspx");

            }
            else
            {
                log.Error("Page Load failed : " );
                lblMessage.Visible = true;
                lblMessage.Text = "<br>Tài khoản hoặc mật khẩu không đúng.";
                
                return;
            }
        }
        catch(Exception ex)
        {
            if (log.IsDebugEnabled)
            {
                log.Debug("Application loaded successfully.");
            }
            if (log.IsErrorEnabled)
            {
                
                log.Error("Page Load failed : " + ex.Message);
            }
        }
        
        
    }
}